﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YX
{
    enum Direction
    {
        Up,
        Down,
        Left,
        Right
    }
    /// <summary>
    /// 所有对象的基础类,封装着所有成员
    /// </summary>
    abstract class BaseClass
    {
        //坐标，宽高，速度，生命，方向
        public int X 
        {
            get; 
            set; 
        }
        public int Y
        {
            get;
            set;
        }
        public int Width
        {
            get;
            set;
        }
        public int Hiegth
        {
            get;
            set;
        }
        public int Speed
        {
            get;
            set;
        }
        public int Life
        {
            get;
            set;
        }

        public Direction Dir
        {
            get;
            set;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="hieght"></param>
        /// <param name="speed"></param>
        /// <param name="life"></param>
        /// <param name="dir"></param>
        public BaseClass(int x,int y,int width,int hieght,int speed,int life,Direction dir)
       {
            this.X = x;
            this.Y = y;
            this.Width = width;
            this.Hiegth = hieght;
            this.Speed = speed;
            this.Life = life;
            this.Dir = dir;
       }

        //爆炸图片的坐标
        public BaseClass(int x,int y)
        {
            this.X = x;
            this.Y = y;
        }

        //抽象一个绘图类，供每个不同成员绘制自己时候用
        public abstract void Draw(Graphics g);

        //获取当前的矩形
        public Rectangle GetRectangle()
        {
            return new Rectangle(this.X, this.Y, this.Width, this.Hiegth);
        }

        /// <summary>
        /// 虚方法子类可以重写可以不重写
        /// </summary>
        public virtual void Move()
        {
            switch(this.Dir)
            {
                case Direction.Up:
                    this.Y -= Speed;
                    break;
                case Direction.Down:
                    this.Y += Speed;
                    break;
                case Direction.Left:
                    this.X -= Speed;
                    break;
                case Direction.Right:
                    this.X += Speed;
                    break;
            }

            //判断是否超出窗体
            if(this.X<=0)
            {
                this.X = 0;
            }
            if(this.X>=400)
            {
                this.X=400;
            }
            if (this.Y <= 0)
            {
                this.Y = 0;
            }
            if (this.Y >= 700)
            {
                this.Y = 700;
            }
        }
    }
}
